// --------------------------------------------------------------------
    // UDP客户端实现
// --------------------------------------------------------------------

#include <string>
#include <iostream>
#include "uclient.hpp"
#include <sys/socket.h>
#include <netinet/in.h>

namespace ymbxSock{

udpCli::udpCli(const std::string& ip,uint16_t port):_ip(ip),_port(port){
    CreateLog("udpclient");
    _sock.Socket("udp");
}
void udpCli::Start(){
    while(1){
        std::cout<<"请输入>>>";
        std::string mes;
        std::cin>>mes;
        _sock.Sendto(_ip,_port,mes);
        sleep(1);
        std::string rmes;
        std::string ip;
        uint16_t port;
        _sock.Recvfrom(&ip,&port,&rmes);
        std::cout<<"接收到来自"<<ip<<":"<<port<<"的消息>>>"<<rmes<<std::endl;
    }
}
udpCli::~udpCli(){
    _sock.Close();
}
}


int main(int argc,char* argv[]){
    if(argc!=3){
        ymbxSock::CliPromote();
        abort();
    }
    std::string ip=argv[1];
    uint16_t port=std::stoi(argv[2]);
    ymbxSock::udpCli cli(ip,port);
    cli.Start();
    return 0;
}